/**
 * usb连接
 */
// #ifdef APP-PLUS
import * as module from "@/uni_modules/leven-uts-printer"
import { usePluginStoreWithOut } from '@/store/plugin'
const plugin = usePluginStoreWithOut()
// #endif

export class UsbConnect {
  constructor() {

  }

  //usb连接
  connect (deviceName) {
    module.usbConnect({
      deviceName: deviceName
    }, res => {
      if (res.code == 0) {
        //连接成功
        plugin.isConnect = true
        plugin.connectDeviceName = deviceName
      } else {
        // uni.$u.toast(res.message);
        console.log(res.message)
      }
    })
  }

  //获取所有USB设备
  getAllUsbDevices () {
    return new Promise(resolve => {
      module.getAllUsbDevices(res => {
        resolve(res)
      })
    })
  }

  //获取所有usb打印机设备
  getAllUsbPrinterDevices () {
    return new Promise(resolve => {
      module.getAllUsbPrinterDevices(res => {
        resolve(res)
      })
    })
  }
}
